package com.shop.cereshop.app.controller.location;
import com.shop.cereshop.app.service.location.CityService;
import com.shop.cereshop.commons.constant.CoReturnFormat;
import com.shop.cereshop.commons.domain.city.CereCityDetail;
import com.shop.cereshop.commons.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("app/city")
@Api(value = "获取用户所城市在地理位置接口", tags = "获取用户所在地理位置接口")
public class CityController {

    @Autowired
    private CityService cityService;

    @GetMapping("/findByCoordinates")
    @ApiOperation(value = "获取用户城市所在地理位置接口")
    public Result<CereCityDetail> findCityByCoordinates(
            @RequestParam Double lon,
            @RequestParam Double lat
    ) {
        CereCityDetail cityDetail = cityService.findCityByCoordinates(lon, lat);
        if (cityDetail != null) {
            return new Result<>(cityDetail, CoReturnFormat.SUCCESS);
        } else {
            // 如果没有找到匹配的城市，抛出自定义异常
//            throw new CityException("9000", "用户所在城市不在定位范围内");

            return new Result<>(cityDetail, CoReturnFormat.PARAM_INVALID);
        }
    }
}



